#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;
using PII = pair<int, int>;
const int N = 1010;

int n, m, sx, sy, d;
int g[N][N];
bool st[N][N];

PII q[N * N];
int dis[4][2] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}};

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int T;
    cin >> T;
    while(T--){
        cin >> n >> m >> sx >> sy >> d;

        if(abs(n - sx) + abs(m - sy) <= d){
            cout << "-1" << '\n';
            continue;
        }

        if(sx + d >= n && sx - d <= 1){
            cout << "-1" << '\n';
            continue;
        }

        if(sy + d >= m && sy - d <= 1){
            cout << "-1" << '\n';
            continue;
        }

        if(sx + d >= n && sy + d >= m){
            cout << "-1" << '\n';
            continue;
        }

        if(sx - d <= 1 && sy - d <= 1){
            cout << "-1" << '\n';
            continue;
        }

        cout << n + m - 2 << '\n';
    }



    return 0;
}